package com.trkj.service.lzs;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.lzs.JobseekersmasterdateDAO;
import com.trkj.dao.lzs.JobseekersregisterDAO;
import com.trkj.dao.lzs.RecruitAdministrationDAO;
import com.trkj.dao.lzs.RecruitapplyDAO1;
import com.trkj.dao.lzs.RecruitplanDAO1;
import com.trkj.dao.lzs.RecruitprocessDAO1;
import com.trkj.dao.lzs.PositionDAO;
import com.trkj.pojo.Jobseekersmasterdate;
import com.trkj.pojo.Jobseekersregister;
import com.trkj.pojo.Position;
import com.trkj.pojo.RecruitAdministration;
import com.trkj.pojo.Recruitapply;
import com.trkj.pojo.Recruitplan;
import com.trkj.pojo.Recruitprocess;
import com.trkj.pojo.SocialSecurity;

@Service
@Transactional(rollbackFor=Exception.class)
public class RecruitmentService {
	//招聘流程模板  
	//Recruitment process template
	@Autowired
	RecruitprocessDAO1 recruitmentPTDAO;
	@Autowired
	RecruitapplyDAO1 recruitapplyDAO;
	@Autowired
	RecruitplanDAO1  recruitplanDAO;
	@Autowired
	JobseekersmasterdateDAO jsmdDAO;
	@Autowired
	JobseekersregisterDAO jsrDAO;
	@Autowired
	RecruitAdministrationDAO radmDAO;
	@Autowired
	PositionDAO PositionDAO;
	public List<Recruitprocess> findAllRe(){
		return recruitmentPTDAO.findAll();
	}
	public void addRecruitprocess(Recruitprocess re) {
		recruitmentPTDAO.save(re);
	}
	public Recruitprocess findAllReLoad(Long reId) {
		if(recruitmentPTDAO.exists(reId)){
			return recruitmentPTDAO.findOne(reId);
		}
		return null;
	}
	public boolean dltRe(Long reId) {
		if(recruitmentPTDAO.exists(reId)){
			recruitmentPTDAO.delete(reId);
			 return true;
		}
		return false;
	}
	public boolean editRecruitprocess(Long reId, String reproName, String reproPerson) {
		if(recruitmentPTDAO.exists(reId)){
			Recruitprocess re = recruitmentPTDAO.findOne(reId);
			re.setReproName(reproName);
			re.setReproPerson(reproPerson);
			recruitmentPTDAO.save(re);
			 return true;
		}
		return false;
		}
	
	
	  //模糊查询
		//根据姓名查找
		public  List<Recruitprocess> queryByName (String  text){

			return recruitmentPTDAO.queryByName("%" + text + "%");
		}
	//招聘申请单
	public List<Recruitapply> findAllRa(){
		return recruitapplyDAO.findAll();
	}
	public void addRecruitapply(Recruitapply re) {
		recruitapplyDAO.save(re);
	}
	public Recruitapply findAllRaLoad(Long reId) {
		if(recruitapplyDAO.exists(reId)){
			return recruitapplyDAO.findOne(reId);
		}
		return null;
	}
	public boolean dltRa(Long reId) {
		if(recruitapplyDAO.exists(reId)){
			recruitapplyDAO.delete(reId);
			 return true;
		}
		return false;
	}
	
	public boolean editRecruitapply(Long reId, String reappExplain, BigDecimal reappPlan) {
		if(recruitapplyDAO.exists(reId)){
			Recruitapply re = recruitapplyDAO.findOne(reId);
			re.setReappExplain(reappExplain);
			re.setReappPlan(reappPlan);
			recruitapplyDAO.save(re);
			 return true;
		}
		return false;
		}
	

	  //模糊查询
		//根据姓名查找
		public  List<Recruitapply> RecruitapplyqueryByName (String  text){

			return recruitapplyDAO.RecruitapplyqueryByName("%" + text + "%");
		}
	
	
	
	
	
	
	
	
	
	
	
	
	//申请计划
		public List<Recruitplan> findAllrplan(){
			return recruitplanDAO.findAll();
		}
		public void addrplan(Recruitplan re) {
			recruitplanDAO.save(re);
		}
		public Recruitplan findAllrplanLoad(Long reId) {
			if(recruitplanDAO.exists(reId)){
				return recruitplanDAO.findOne(reId);
			}
			return null;
		}
		public boolean dltrplan(Long reId) {
			if(recruitplanDAO.exists(reId)){
				recruitplanDAO.delete(reId);
				 return true;
			}
			return false;
		}
		public boolean editrplan(Long reId, String reappExplain, BigDecimal reappPlan) {
			if(recruitplanDAO.exists(reId)){
				Recruitplan re = recruitplanDAO.findOne(reId);
				
				recruitplanDAO.save(re);
				 return true;
			}
			return false;
			}
		
		
		
		
		
		
		
		
		//求职人员主数据
				public List<Jobseekersmasterdate> findAlljsmd(){
					return jsmdDAO.findAll();
				}
				public void addjsmd(Jobseekersmasterdate re) {
					jsmdDAO.save(re);
				}
				public Jobseekersmasterdate findAlljsmdLoad(Long reId) {
					if(jsmdDAO.exists(reId)){
						return jsmdDAO.findOne(reId);
					}
					return null;
				}
				public boolean dltjsmd(Long reId) {
					if(jsmdDAO.exists(reId)){
						jsmdDAO.delete(reId);
						 return true;
					}
					return false;
				}
				public boolean editjsmd(Jobseekersmasterdate js) {
					if(jsmdDAO.exists(js.getJsmdId())){
						Jobseekersmasterdate re = jsmdDAO.findOne(js.getJsmdId());
						js.setJobseekersregister(re.getJobseekersregister());
						jsmdDAO.save(js);
						 return true;
					}
					return false;
					}
				
				
				

				  //模糊查询
					//根据姓名查找
					public  List<Jobseekersmasterdate> JobseekersmasterdatequeryByName (String  text){

						return jsmdDAO.JobseekersmasterdatequeryByName("%" + text + "%");
					}
				

				//求职人员登记
				public List<Jobseekersregister> findAlljsr(){
					return jsrDAO.findAll();
				}
				public boolean addjsr(Jobseekersregister re, Long recplanId1, Long positionId1) {
					if(recruitplanDAO.exists(recplanId1)&&PositionDAO.exists(positionId1)){
						Jobseekersregister re1 = jsrDAO.findOne(re.getJsrId());
						re.setRecruitplan(recruitplanDAO.findOne(recplanId1));
						re.setPosition(PositionDAO.findOne(positionId1));
						jsrDAO.save(re);
						 return true;
					}
					return false;
					}
				public Jobseekersregister findAlljsrLoad(Long jsrId) {
					if(jsrDAO.exists(jsrId)){
						return jsrDAO.findOne(jsrId);
					}
					return null;
				}
				public boolean dltjsr(Long jsrId) {
					if(jsrDAO.exists(jsrId)){
						jsrDAO.delete(jsrId);
						 return true;
					}
					return false;
				}
				public boolean editjsr(Jobseekersregister re, Long recplanId1, Long positionId1) {
					if(jsrDAO.exists(re.getJsrId())&&recruitplanDAO.exists(recplanId1)&&PositionDAO.exists(positionId1)){
						Jobseekersregister re1 = jsrDAO.findOne(re.getJsrId());
						re.setRecruitplan(recruitplanDAO.findOne(recplanId1));
						re.setPosition(PositionDAO.findOne(positionId1));
						jsrDAO.save(re);
						 return true;
					}
					return false;
					}
				public Jobseekersregister findAllJsrLoad(Long jsrId) {
					return jsrDAO.findOne(jsrId);
				}
				

				  //模糊查询
					//根据姓名查找
					public  List<Jobseekersregister> Jobseekersregistercx (String  text){

						return jsrDAO.jsrqueryByName("%" + text + "%");
					}
				
				
				
				
				

				//招聘管理
				public List<RecruitAdministration> findAllradm(){
					return radmDAO.findAll();
				}
				public boolean addradm(RecruitAdministration re, Long recplanId1, Long positionId1) {
					if(recruitplanDAO.exists(recplanId1)&&PositionDAO.exists(positionId1)){
						RecruitAdministration re1 = radmDAO.findOne(re.getReadmiId());
						re.setRecruitplan(recruitplanDAO.findOne(recplanId1));
						re.setPosition(PositionDAO.findOne(positionId1));
						radmDAO.save(re);
						 return true;
					}
					return false;
					}
				public RecruitAdministration findAllradmLoad(Long radmId) {
					if(radmDAO.exists(radmId)){
						return radmDAO.findOne(radmId);
					}
					return null;
				}
				public boolean dltradm(Long radmId) {
					if(radmDAO.exists(radmId)){
						radmDAO.delete(radmId);
						 return true;
					}
					return false;
				}
				public boolean editradm(RecruitAdministration re, Long recplanId1, Long positionId1) {
					if(radmDAO.exists(re.getReadmiId())&&recruitplanDAO.exists(recplanId1)&&PositionDAO.exists(positionId1)){
						RecruitAdministration re1 = radmDAO.findOne(re.getReadmiId());
						re.setRecruitplan(recruitplanDAO.findOne(recplanId1));
						re.setPosition(PositionDAO.findOne(positionId1));
						radmDAO.save(re);
						 return true;
					}
					return false;
					}
				
				
				
				
				
				
				//
				
				public Position findPositionIdLoad(Long positionId) {
					if(PositionDAO.exists(positionId)){
						return PositionDAO.findOne(positionId);
					}
					return null;
				}
				public List<Position> findAllPosition() {
					return PositionDAO.findAll();
				}

}
